<template>
  <view class="container" style="position: relative;">
    <cu-custom bgColor="bg-blue" :isBack="true">
      <block slot="content">订单</block>
    </cu-custom>
    <view class="qrcodeModal bg-white" v-if="dataModel.findIndex(a=>a.code==8000)!=-1">
      <u-search :showAction="true" v-model="searchOrderNum" placeholder="请输入订单编号" actionText="搜索" @search="loadmore('refresh')"
        @custom="loadmore('refresh')"></u-search>
    </view>
    <view class="padding padding-top-xs">
      <scroll-view scroll-y="true" @scrolltolower="loadmore" style="max-height: calc(100vh - 220rpx);">
        <view class="dateItem" v-for="(item,index) in indexList" :key="index" @click="navTo(item)">
          <view class="headBox flex justify-between align-center">
            <view class="title">订单号：{{item.forderNo}}</view>
            <view class="text-blue">查看详情</view>
          </view>
          <view class="padding-tb">
            <view class="title" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">客户：{{item.customerName}}</view>
          </view>
          <view class="padding-bottom flex align-center justify-between">
            <view class="title">下单日期：{{item.acceptOrderTime||'-'}}</view>
          </view>
          <view class="padding-bottom flex align-center justify-between">
            <view class="title">交货日期：{{item.deliveryTime||'-'}}</view>
          </view>
          <view class="padding-bottom flex align-center justify-between">
            <view class="title">设计师：{{item.designerName||'-'}}</view>
          </view>
          <view class="padding-bottom flex align-center justify-between">
            <view class="title">订单状态：{{filterStatus(item.status)}}</view>
          </view>
        </view>
      </scroll-view>
    </view>
    <view style="width: 100%;position: fixed;
    bottom: 100rpx;" class="flex align-center justify-center">
      <image src="/static/tab/icon_sao.png" style="width: 180rpx;" mode="widthFix" @click="setSaoMa"></image>
    </view>
    <u-notify ref="uNotify"></u-notify>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from 'vuex';
  export default {
    components: {},
    data() {
      return {
        statusList: [{
            value: 0,
            label: "工厂待审核",
          },
          {
            value: -10,
            label: "待推送",
          },
          {
            value: 10,
            label: "待分配",
          },
          {
            value: 20,
            label: "设计",
          },
          {
            value: 30,
            label: "校对",
          },
          {
            value: 40,
            label: "校对审核未通过",
          },
          {
            value: 50,
            label: "打印",
          },
          {
            value: 60,
            label: "转印",
          },
          {
            value: 70,
            label: "裁切",
          },
          {
            value: 80,
            label: "下货",
          },
          {
            value: 90,
            label: "车缝",
          },
          {
            value: 100,
            label: "质检",
          },
          {
            value: 110,
            label: "包装",
          },
          {
            value: 120,
            label: "物流",
          },
          {
            value: 130,
            label: "发货",
          },
          {
            value: 140,
            label: "完成",
          },
          {
            value: 150,
            label: "已反审",
          },
          {
            value: 170,
            label: "关闭",
          }
        ],
        searchOrderNum: '',
        CustomBar: this.CustomBar,
        indexList: [],
        curNow: 0,
        pageindex: 1,
        queryType: 3,
        dataModel: [],
        loadingType: 'more', //加载更多状态
      };
    },
    onPageScroll(e) {},
    onReady() {},
    onLoad(option) {},
    onShow() {
      setTimeout(() => {
        this.dataModel = this.userInfo && this.userInfo.smyRolePermissionsQueryVo ? this.userInfo.smyRolePermissionsQueryVo.smyUserPermissionsDetailVo : [];
      }, 500)
      this.loadmore('refresh')
    },
    computed: {
      ...mapState(['userInfo'])
    },
    methods: {
      filterStatus(id) {
        let arr = this.statusList.filter((item) => {
          return item.value == id;
        });
        return arr.length > 0 && arr[0].label;
      },
      setSaoMa(e) {
        let _this = this;
        uni.scanCode({
          scanType: ['barCode', 'qrCode'], //扫码类型 
          autoZoom: true, //是否启用自动放大，默认启用
          success: (res) => {
            let model = {
              forderNo: res.result
            }
            this.navTo(model)
          }
        });
      },
      navTo(model) {
        uni.navigateTo({
          url: `/pages/index/orderDetail?orderNo=${model.forderNo}`
        })
      },
      async loadmore(type = 'add', loading) {
        let _this = this;
        //没有更多直接返回
        if (type === 'refresh') {
          this.pageindex = 1;
          this.loadingType = 'more'
        }
        if (this.loadingType === 'nomore') {
          return;
        }
        if (type === 'add') {
          this.loadingType = 'loading';
        } else {
          this.loadingType = 'more'
        }
        this.$ComFunJS.ajax({
          method: "post",
          url: `/system/order/list?pageSize=10&pageNo=${this.pageindex}`,
          data: {
            pageNo: this.pageindex,
            status: [0, 10, 20, 30, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 170],
            pageSize: 10,
            forderNo: this.searchOrderNum,
            searchType: 0
          },
          success: (res) => {
            if (res.code == 200) {
              let List = res.rows ? res.rows : [];
              if (type === 'refresh') {
                this.indexList = [];
              }
              if (List.length > 0) {
                _this.pageindex++
              }
              this.indexList = this.indexList.concat(List);
              //判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
              this.loadingType = res.rows && res.rows.length >= 10 ? 'more' : 'nomore';
              if (type === 'refresh') {
                if (loading == 1) {
                  uni.hideLoading()
                } else {
                  uni.stopPullDownRefresh();
                }
              }
            }
          }
        })
      }
    },
  }
</script>

<style lang="scss">
  page {
    background: #F5F6F7;
  }

  .modelShowTitle {
    font-size: 32rpx;
    font-weight: 500;
    color: rgba(49, 55, 64, 1);
    margin-bottom: 12rpx;
  }

  .inputPlace {
    color: rgba(0, 0, 0, 0.5);
  }

  .modelInput {
    width: 100%;
    height: 96rpx;
    background: rgba(165, 168, 173, .08);
    border-radius: 12rpx;
    min-height: 48px;
    padding: 14rpx;
    display: flex;
    align-items: center;

    input {
      width: 100%;
      color: #2a2a2a;
      background: none;
      border: none;
    }
  }

  .qrcodeModal2 {
    padding: 30upx 160upx;
    position: absolute;
    width: 100%;
    top: 300rpx;
    opacity: .2;

    .qrcodeText {
      position: relative;
      font-size: 28upx;
      font-weight: 500;
      letter-spacing: 0px;
      line-height: 28.96px;
      color: rgba(41, 63, 102, 1);
      text-align: center;
      top: -100upx;
    }
  }

  .qrcodeModal {
    padding: 30upx;
    width: 100%;

    .qrcodeText {
      position: relative;
      font-size: 40upx;
      font-weight: 500;
      letter-spacing: 0px;
      line-height: 28.96px;
      color: rgba(41, 63, 102, 1);
      text-align: center;
      top: -100upx;
    }

    .qrcodeIntro {
      font-size: 28upx;
      position: relative;
      font-weight: 400;
      color: rgba(154, 165, 184, 1);
      text-align: center;
      top: -90upx
    }
  }

  .qrcodeButton {
    width: 100%;
    height: 96upx;
    opacity: 1;
    border-radius: 122upx;
    background: linear-gradient(180deg, rgba(18, 96, 252, 1) 0%, rgba(38, 129, 255, 1) 100%);
    box-shadow: 0px 17upx 51upx rgba(233, 239, 245, 1);
    text-align: center;
    font-size: 28upx;
    color: #fff;
    line-height: 96upx;
    letter-spacing: 2upx;
  }

  .u-modal__content {
    flex-direction: column !important;
  }

  .cancleBtn {
    width: 260.62upx;
    height: 80upx;
    opacity: 1;
    border-radius: 12rpx;
    background: rgba(0, 0, 0, 0.05);
    font-size: 32upx;
    font-weight: 500;
    letter-spacing: 6px;
    color: rgba(49, 55, 64, 1);

    &.sumbit {
      background: linear-gradient(180deg, rgba(18, 96, 252, 1) 0%, rgba(38, 129, 255, 1) 100%);
      color: #FFFFFF;
    }
  }

  .dateItem {
    width: 100%;
    opacity: 1;
    border-radius: 16rpx;
    background: rgba(255, 255, 255, 1);
    padding: 0 30rpx;
    margin-top: 16rpx;

    .headBox {
      border-bottom: 1px solid rgba(154, 165, 184, 0.11);
      padding: 20rpx 0;
    }

    .title {
      font-size: 28rpx;
      font-weight: 500;
      color: rgba(49, 55, 64, 1);
      text-align: left;
    }

    .date {
      font-size: 24rpx;
      font-weight: 400;
      color: rgba(130, 132, 135, 1);
      text-align: left;
    }

    .allPrice {
      font-size: 34rpx;
      font-weight: 700;
      color: rgba(18, 96, 252, 1);
    }

    .price {
      font-size: 32rpx;
      font-weight: 400;
      color: rgba(130, 132, 135, 1);
    }
  }
</style>